﻿@using QLGT_2.Models;

@{
    AjaxOptions aj=new AjaxOptions { 
        InsertionMode = InsertionMode.Replace, 
        UpdateTargetId = "content-main" ,
        LoadingElementId = "loading-icon",
        OnFailure = "AjaxFailure",
        OnBegin = "AjaxBegin",
        OnComplete = "AjaxComplete"
    };

    if (Session["TenDangNhap"] == null || Session["ChucNang"] == null)
    {
        Response.Redirect("~/Home/Login");
    }

    QLGTContext db = new QLGTContext();
    var chucNang = Session["ChucNang"] as int[];
    IEnumerable<tbl_ChucNang> tbl_chucNangLoad = db.tbl_ChucNangs.Where(m => chucNang.Contains(m.MaCN));
}

 
<aside class="sidebar offscreen-left">

    <nav id="main-navigation" class="main-navigation" data-height="auto" data-size="6px" data-distance="0" data-rail-visible="true" data-wheel-step="10">
        <ul class="nav mb20">
            @*<li>

                @Ajax.ActionLink("Trang đầu", "Index", "Home", aj)
            </li>*@
            <li>
                <a href="/Home">
                    <i class="glyphicon glyphicon-globe"></i>
                    <span>Trang chủ</span>
                </a>
            </li>

            @RenderMenuItem(tbl_chucNangLoad, 0, aj)

            @helper RenderMenuItem(IEnumerable<tbl_ChucNang> tbl_chucNangLoad, int role, AjaxOptions aj)
            {
                var list_role = tbl_chucNangLoad.Where(m => m.MaCNCha == role && m.TrangThai == 1 && m.LaMenu == 1).OrderBy(m => m.ThuTuHienThi);
                foreach (var item in list_role)
                {
                    int count_child = tbl_chucNangLoad.Where(m => m.MaCNCha == item.MaCN && m.TrangThai == 1 && m.LaMenu == 1).Count();

                    <li>
                        @if (count_child > 0)
                        {
                            <a href="javascript:;">
                                <i class="toggle-accordion glyphicon glyphicon-chevron-down"></i>
                                <i class="glyphicon @item.CSSIcon"></i>
                                <span>@item.TenCN</span>
                            </a>

                            <ul class="sub-menu">
                                @RenderMenuItem(tbl_chucNangLoad, item.MaCN, aj)
                            </ul>
                        }
                        else
                        {
                            string[] Link = item.Link.TrimEnd().Split('/');
                            string Controller = Link[0].ToString().TrimEnd();
                            string Action = "";
                            if (Link.Count() > 1)
                            {
                                Action = Link[1].ToString().TrimEnd();
                            }
                            if (Action != "")
                            {
                                @Ajax.ActionLink(item.TenCN, Action, Controller, aj);
                            }

                        }
                    </li>
                }
            }
                    </ul>


        
    </nav>
</aside>




